package com.car.controller;

import com.car.model.auto.Message;

import com.car.service.IMessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/message")
@CrossOrigin
public class MessageController {

    @Resource
    private IMessageService iMessageService;

    /*查询车辆*/
    @GetMapping("/getMessage")
    public List<Message> getMessage(){
        return iMessageService.list();
    }

    /*通过id查询车辆*/
    @GetMapping("/getMessageById/{id}")
    public Message getMessageById(@PathVariable("id") int id){
        return iMessageService.getById(id);
    }

    /*修改车辆*/
    @PostMapping("/updateMessage")
    public void updateMessage(@RequestBody Message message){
        iMessageService.updateById(message);
    }

    /*添加车辆*/
    @PostMapping("/setMessage")
    public void setMessage(@RequestBody Message message){
        iMessageService.save(message);
    }

    /*删除车辆*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iMessageService.removeById(id);
    }
}
